/**
 * DOM 操作封装
 */

//获取单个DOM节点
function getEle(selector) {
	return document.querySelector(selector);
}

//获取多个DOM节点
function getEles(selector) {
	return document.querySelectorAll(selector);
}

//封装文档加载事件
function ready(callback) {
	window.addEventListener("DOMContentLoaded", function () {
		//当前页面的具体功能
		callback(); //把 使用时function中的功能全部执行到这个位置
	});
}
// 点击跳转页面
function jump(dom, target) {
	getEle(dom).addEventListener("click", function () {
		location.href = `${target}.html`;
	});
}

//判断是否有toen

let local = require("./local.js")

function isLogin() {
	let tk = local.get("tk")
	if (!tk) {
		location.href = "register.html"
	}

}


// 首页尾部
function contFooter(obj) {
	getEle("body").innerHTML += `<footer class="pfix">
			<ul class="df">
			  <li class="f18">
			  <a href="home.html " ${obj == "home" ? "class=active" : ""}
		   ><span class="iconfont">&#xe600;</span>
		   </span>
		   首页</a>
		   </li>
		   <li class="f18">
			  <a href="
		   sport.html" ${obj == "sport" ? "class=active" : ""}
		  ><span class="icon iconfont">&#xee4f;</span>运动</a>
		   </li>
		   <li class="f18">
			   <a href="circle.html" ${obj == "circle" ? "class=active" : ""
		}><span class="icon iconfont">&#xe603;</span>圈子</a>
		   </li>
		   <li class="f18">
			  <a href="my.html" ${obj == "my" ? "class=active" : ""
		}><span class="icon iconfont">&#xe606;</span>我的</a>
		   </li>
		  </ul>
		  </footer>`;;
}


//导出
module.exports = {
	getEle,
	getEles,
	ready,
	jump,
	isLogin,
	contFooter
};
